<?php

namespace api\controller;

use common\controller\VerifyController;
use common\exception\LogicException;
use common\service\EntityAbolitionOrEnableService;
use common\service\ShotService;
use think\Exception;
use think\Request;
use think\Response;

class ShotController extends VerifyController
{

    public $shotService;
    private $entityAbolitionOrEnableService;

    public function __construct()
    {
        parent::__construct();
        $this->shotService = new ShotService();
        $this->entityAbolitionOrEnableService = EntityAbolitionOrEnableService::getInstance();
    }

    /**
     * 镜头状态废除
     * @param Request $request
     * @return Response|void
     * @throws \Throwable
     */
    public function shotStatus(Request $request)
    {
        try {
            $param = $request->param();
            $res = $this->entityAbolitionOrEnableService->entityAbolitionOrEnabling($param['data']['status'], $param['data']);
//            $res = $this->shotService->shotAbolitionOrEnabling($param['data']['status'], $param['data']);
            return json(success_response('OK', $res));
        } catch (LogicException $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }


    /**
     * 序列状态废除
     * @param Request $request
     * @return Response|void
     * @throws Exception
     */
    public function seqStatus(Request $request)
    {
        try {
            $param = $request->param();
            $res = $this->shotService->seqAbolitionOrEnabling($param['data']['status'], $param['data']);
            return json(success_response('OK', $res));
        } catch (LogicException $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 关联分镜列表
     * @param Request $request
     * @return Response|void
     */
    public function relateStoryboardList(Request $request)
    {
        try {
            $param = $request->param();
            $res = $this->shotService->relateStoryboardList($param['param']['id'], $param['param']);
            return json(success_response('OK', $res));
        } catch (LogicException $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 关联分镜列表
     * @param Request $request
     * @return Response|void
     */
    public function unRelateStoryboardList(Request $request)
    {
        try {
            $param = $request->param();
            $res = $this->shotService->unRelateStoryboardList($param['param']['id'], $param['param']);
            return json(success_response('OK', $res));
        } catch (LogicException $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 操作镜头相关镜头
     * @param Request $request
     * @return Response|void
     * @throws Exception
     */
    public function setRelateStoryboard(Request $request)
    {
        try {
            $param = $request->param()['param'];
            $res = $this->shotService->setRelateStoryboard($param['id'], $param['relate_id_list'], $param['action']);
            return json(success_response('OK', $res));
        } catch (LogicException $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 操作关键镜头
     * @param Request $request
     * @return Response|void
     */
    public function setKeyShot(Request $request)
    {
        try {
            $param = $request->param()['param'];
            $res = $this->shotService->setKeyShot($param['shot_id_list'], $param['is_key_shot']);
            return json(success_response('OK', $res));
        } catch (LogicException $e) {
            throw_strack_exception($e->getMessage(), $e->getCode());
        }
    }
}
